<script setup>
import { deleteUserAPI, getBaseInfo, jwt } from "@/apis/login";
import axios from "axios";
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();
const msg = ref("");

onMounted(async () => {
  const res = await getBaseInfo();
  msg.value = res.msg;
});

const handleLogout = () => {
  const token = localStorage.getItem("token");
  if (token) {
    localStorage.removeItem("token");
  }
  router.push("/login");
};

const handleJwt = async () => {
  const token = localStorage.getItem("token");
  const res = await jwt({
    token: token,
  });
};

const handleUpload = async () => {
  router.push("/uploadpic");
};

const addUser = async () => {
  router.push("/adduser");
};

const deleteUser = async () => {
  const res = await deleteUserAPI();
};

const editUser = () => {
  router.push("/edit");
};
</script>

<template>
  <h1>{{ msg }}</h1>
  <button @click="handleUpload">上传图片功能页</button>
  <br />
  <div class="index"><button @click="handleLogout">退出登陆</button></div>
  <button @click="handleJwt">解密jwt</button>
  <br />
  <button @click="addUser">新增用户</button>
  <br />
  <button @click="editUser">编辑用户信息</button>
  <br />
  <button @click="deleteUser">删除用户</button>
</template>

<style lang="scss">
//
</style>
